#include <iostream>
#include <queue>
using namespace std;
const int N=1e3+10;
int main()
{
  int n;
  cin>>n;
  priority_queue<int,vector<int>,greater<int>>q;
  for(int i=1;i<=n;i++){
    int x;
    cin>>x;
    q.push(x);
  }
  int ans=0;
  if(n==1) ans=q.top();
  else{
  	 while(q.size()!=1){
    int x1=q.top();
    q.pop();
    int x2=q.top();
    q.pop();
    ans+=x1+x2;
    q.push(x1+x2);
  }
  }
  cout<<ans<<endl;
  return 0;
}
